package com.itheima.test5case1;

import java.util.ArrayList;
import java.util.Collections;

public class MyThread extends Thread {

    static ArrayList<Integer> list = new ArrayList<>();
    //两个抽奖箱共用一个奖池
    static {
        Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700);
    }

    @Override
    public void run() {
        while(true){
            synchronized(MyThread.class){
                if(list.size()==0){
                    System.out.println("奖都被抽完了");
                    break;
                }else {
                    //随机
                    Collections.shuffle(list);
                    System.out.println(Thread.currentThread().getName()+"产生了一个"+list.get(0)+"的奖项");
                    //删除抽取到的奖项
                    list.remove(0);

                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
